var express = require('express');
var router = express.Router();
var mysql = require('mysql');
const { mysqlCreate } = require('./utils');
//连接数据库
let conn = mysqlCreate();

//获取所有文章
router.get('/', (req, res) => {
  conn = mysql.createConnection(conn.config); 
  var sql = `SELECT * FROM user`;
  var { username } = req.body;
  console.log(req.query)
  conn.connect();
  conn.query(sql, function (err, result) {
    if(err){
      console.log('[SELECT ERROR] - ',err.message);
      res.json({ code: -1})
    }else{
      //查询数据
      res.json({code:10000, message: result})
    } 
  });
  conn.end();
})

module.exports = router;
